#!/bin/sh
main()
{
. $DOCUMENT_ROOT/apps/home/header.tpl.sh
header_html
eval `cat $DOCUMENT_ROOT/apps/$FORM_app/arp_defense.conf`
cat <<'EOF'
<script>
$(function(){
  $('#post_set_arp_defense').on('submit', function(e){
    e.preventDefault();
    var data = "app=arp_defense&action=post_set_arp_defense&"+$(this).serialize();
    var url = 'index.cgi';
    Ha.common.ajax(url, 'json', data, 'post', 'ajax-fluid');
  });
});
</script>
EOF
cat <<EOF
		<div class="pure-g">
			<div class="l-box-lrg pure-u-1 pure-u-md-1-2">
				<h3>Arp 防御</h3>
				<form class="pure-form pure-form-stacked" id="post_set_arp_defense">
					<fieldset>

					<div class="pure-u-1">
						<label>开/关
							<select name="enabled">
								<option value="0" `[ $enabled -eq 0 ] && echo selected`>禁用</option>
								<option value="1" `[ $enabled -ne 0 ] && echo selected`>启用</option>
							</select>
						</label>
						<button class="pure-button">保存</button>
					</div>

					</fieldset>
				</form>
				<br/>
				<br/>
			</div>
			<div class="l-box-lrg pure-u-1 pure-u-md-1-2">
				<div class="content">
				<h3>说明<h3>
				<p>打开可以防御内网arp攻击.</p>
				</div>
			</div>
		</div>
EOF
footer_html keep_bottom
}
post_set_arp_defense()
{
sed -i "s/enabled=.*/enabled=$FORM_enabled/g" $DOCUMENT_ROOT/apps/arp_defense/arp_defense.conf
$DOCUMENT_ROOT/apps/arp_defense/S400arp_defense.init restart
echo "修改成功!!" | main.sbin output_json 0
}
get_arp_defense_setting()
{
eval `cat $DOCUMENT_ROOT/apps/arp_defense/arp_defense.conf`
cat <<EOF

{"enabled": $enabled}
EOF
}
lang=`main.sbin get_client_lang`
eval `cat $DOCUMENT_ROOT/apps/$FORM_app/i18n/$lang/i18n.conf`
if
[ $is_main_page = 1 ]
then
main
elif [ -n "$FORM_action" ]
then
$FORM_action
fi
